package com.base.springboot.starter.mybatisplus.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.base.common.model.po.UserInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * MybatisPlus entity 封装类
 *
 * @author admin
 * @date 2020/5/19 AM10:15
 */
@Data
@FieldNameConstants
public class GenericEntityExtend extends Model<GenericEntityExtend> implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 数据库 主键
     */
    @ApiModelProperty(value = "主键id")
    protected Long id;

    @ApiModelProperty(value = "创建者ID")
    private String createEmp;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "修改人ID")
    private String modifyEmp;

    @ApiModelProperty(value = "修改时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime modifyTime;

    @ApiModelProperty(value = "删除标记")
    @TableLogic
    private Integer delFlag;

    @ApiModelProperty(value = "所属系统")
    private String btSystem;

    @ApiModelProperty(value = "所属用户")
    private String btUser;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "创建者name")
    private String createEmpName;

    @ApiModelProperty(value = "修改人NAME")
    private String modifyEmpName;

    /**
     * 新增公共属性
     *
     * @param userInfo  用户信息
     */
    public void addUser(UserInfo userInfo) {
        this.setCreateEmp(userInfo.getId().toString());
        this.setCreateEmpName(userInfo.getName());
        this.setBtSystem(userInfo.getBtSystem());
        this.setBtUser(userInfo.getBelongId());
        this.setModifyEmp(userInfo.getId().toString());
        this.setModifyEmpName(userInfo.getName());
    }

    /**
     * 更新公共属性
     *
     * @param userInfo  用户信息
     */
    public void updateUser(UserInfo userInfo) {
        this.setBtSystem(userInfo.getBtSystem());
        this.setBtUser(userInfo.getBelongId());
        this.setModifyEmp(userInfo.getId().toString());
        this.setModifyEmpName(userInfo.getName());
    }

    public static final String REMARK = "remark";

    public static final String CREATE_EMP = "create_emp";

    public static final String CREATE_EMP_NAME = "create_emp_name";

    public static final String CREATE_TIME = "create_time";

    public static final String MODIFY_EMP = "modify_emp";

    public static final String MODIFY_EMP_NAME = "modify_emp_name";

    public static final String MODIFY_TIME = "modify_time";

    public static final String BT_SYSTEM = "bt_system";

    public static final String BT_USER = "bt_user";

    public static final String BT_USER_NAME = "bt_user_name";

    public static final String DEL_FLAG = "del_flag";
}
